<?php
class Pageley_Query_BasicTests extends Pageley_Test_Case {
	private $entity;
	private $type1;
	private $type2;
	
	public function setUp() {
		$string = new Pageley_Domain_Attribute_Basic("string");
		$number = new Pageley_Domain_Attribute_Basic("number");
		$this->type1 = new Pageley_Domain_BasicType(
			"Pageley_Commerce",
			"Article",
			new Pageley_Util_ArrayMap(array(
				"name" => $string,
				"price" => $number
			))
		);
		$this->type2 = new Pageley_Domain_BasicType(
			"Pageley_Commerce",
			"Test",
			new Pageley_Util_ArrayMap(array(
				"name" => $string
			))
		);
		$this->entity = $this->type1->newInstance();
	}
	
	public function testMatchesType() {
		$query = new Pageley_Query_Basic($this->type1);
		$this->assertTrue($query->matches($this->entity));
		$query = new Pageley_Query_Basic($this->type2);
		$this->assertFalse($query->matches($this->entity));
	}
	
	public function testMatchesCondition() {
		$condition = new Pageley_Query_Condition_OrGroup(
			new Pageley_Util_ArrayMap(
				new Pageley_Query_Condition_Equals("price", 5.0),
				new Pageley_Query_Condition_GreaterThan("price", 7.5)
		));
		$query = new Pageley_Query_Basic($this->type1, $condition);
		$this->entity->set("price", 5.0);
		$this->assertTrue($query->matches($this->entity));
		$this->entity->set("price", 7.4);
		$this->assertFalse($query->matches($this->entity));
	}
}